//
//  DDDNativeExpressRewaredVideoVC.m
//  DDDDemo
//
//  Created by lishimin on 2020/2/9.
//  Copyright © 2020 summer. All rights reserved.
//

#import "DDDNativeExpressRewaredVideoVC.h"
#import <DDDAdSdk/DDDNativeExpressRewardedVideoAd.h>
//#import "DDDNativeExpressRewardedVideoAd.h"
#import "MBProgressHUD.h"

@interface DDDNativeExpressRewaredVideoVC ()<DDDNativeExpressRewardedVideoAdDelegate>
@property (nonatomic,strong) DDDNativeExpressRewardedVideoAd *rewardedAd;
@property (nonatomic,strong) UIButton *playBtn;

@end

@implementation DDDNativeExpressRewaredVideoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"激励视频";
    
    CGFloat playBtnW = 150.0;
    CGFloat playBtnH = 45.0;
    CGFloat playBtnX = ([UIScreen mainScreen].bounds.size.width - playBtnW) * 0.5;
    CGFloat playBtnY = 150.0;
    [self.view addSubview:self.playBtn];
    self.playBtn.frame = CGRectMake(playBtnX, playBtnY, playBtnW, playBtnH);
    
    self.rewardedAd = [[DDDNativeExpressRewardedVideoAd alloc] initWithUserId:@"11222"];
    self.rewardedAd.delegate = self;
    [self.rewardedAd loadAdData];
    
}
#pragma mark - 点击事件
- (void)clickBtnAction:(UIButton *)sender {
    
    if (self.rewardedAd.isAdValid) {
        [self.rewardedAd showAdFromRootViewController:self.navigationController];
//        self.button.isValid = NO;
        self.playBtn.userInteractionEnabled = NO;
        [self.playBtn setBackgroundColor:[UIColor grayColor]];
    }
}
#pragma mark - 懒加载
- (UIButton *)playBtn {
    if (!_playBtn) {
        _playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_playBtn setTitle:@"播放激励视频" forState:UIControlStateNormal];
        [_playBtn addTarget:self action:@selector(clickBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [_playBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_playBtn setBackgroundColor:[UIColor grayColor]];
        _playBtn.userInteractionEnabled = NO;
        _playBtn.layer.masksToBounds = YES;
        _playBtn.layer.cornerRadius = 8.0;
    }
    return _playBtn;
}


#pragma mark - DDDNativeExpressRewardedVideoAdDelegate

- (void)nativeExpressRewardedVideoAdDidLoad:(DDDNativeExpressRewardedVideoAd *)rewardedVideoAd {
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.offset = CGPointMake(0, -100);
    hud.label.text = @"material load success";
    [hud hideAnimated:YES afterDelay:2];
}



- (void)nativeExpressRewardedVideoAdDidDownLoadVideo:(DDDNativeExpressRewardedVideoAd *)rewardedVideoAd {
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.offset = CGPointMake(0, -200);
    hud.label.text = @"video load success";
    [hud hideAnimated:YES afterDelay:2];
    
    
    self.playBtn.userInteractionEnabled = YES;
    [self.playBtn setBackgroundColor:[UIColor redColor]];
}


- (void)nativeExpressRewardedVideoAdViewRenderSuccess:(DDDNativeExpressRewardedVideoAd *)rewardedVideoAd {
    
}


- (void)nativeExpressRewardedVideoAdWillVisible:(DDDNativeExpressRewardedVideoAd *)rewardedVideoAd {
    
}

- (void)nativeExpressRewardedVideoAdDidVisible:(DDDNativeExpressRewardedVideoAd *)rewardedVideoAd {
    
}


- (void)nativeExpressRewardedVideoAdWillClose:(DDDNativeExpressRewardedVideoAd *)rewardedVideoAd {
    
}

- (void)nativeExpressRewardedVideoAdDidClose:(DDDNativeExpressRewardedVideoAd *)rewardedVideoAd {
    [self.rewardedAd loadAdData];
}

- (void)nativeExpressRewardedVideoAdDidClick:(DDDNativeExpressRewardedVideoAd *)rewardedVideoAd {
    
}


- (void)nativeExpressRewardedVideoAdDidClickSkip:(DDDNativeExpressRewardedVideoAd *)rewardedVideoAd {
    
}

- (void)nativeExpressRewardedVideoAdDidPlayDidFailWithError:(NSInteger)errorCode {
    NSLog(@"summer--88--%ld",errorCode);
    self.playBtn.userInteractionEnabled = NO;
    [self.playBtn setBackgroundColor:[UIColor grayColor]];
}



@end
